var widthLess1024 = function() {
    if ($(window).width() < 1024) {
        $("#sidebar, #navbar").addClass("collapsed");
        $(".navigation").find(".dropdown.open").removeClass("open");
        $(".navigation").find(".dropdown-menu.animated").removeClass("animated");
        if ($("#sidebar").hasClass("collapsed")) {
            $("#content").animate({
                left: "0px",
                paddingLeft: "55px"/*55*/
            }, 150)
        } else {
            $("#content").animate({
                paddingLeft: "55px"/*55*/
            }, 150)
        }
    } else {
        $("#sidebar, #navbar").removeClass("collapsed");
        if ($("#sidebar").hasClass("collapsed")) {
            $("#content").animate({
                left: "210px",
                paddingLeft: "265px"
            }, 150)
        } else {
            $("#content").animate({
                paddingLeft: "265px"
            }, 150)
        }
    }
};
$(function() {
    $('.sendIframe').click(function(){
        var Url = $(this).find('a').data('url');
        $('.openIframe').attr('src', Url);
    });
    $(".navigation .dropdown").on("show.bs.dropdown", function(d) {
        $(this).find(".dropdown-menu").addClass("animated fadeInLeft")
    });
    $("#sidebar .sidebar-toggle").on("click", function() {
        var d = $(this).data("toggle");
        $(d).toggleClass("collapsed")
    });
    $("#sidebar").niceScroll({
        cursorcolor: "#000000",
        zindex: 999999,
        bouncescroll: true,
        cursoropacitymax: 0.4,
        cursorborder: "",
        cursorborderradius: 8,
        cursorwidth: "6px",
        railalign: "left",
        railoffset: {
            top: 45,
            left: 0
        }
    });
    $("#content").niceScroll({
        cursorcolor: "#000000",
        zindex: 999999,
        bouncescroll: true,
        cursoropacitymax: 0.4,
        cursorborder: "",
        cursorborderradius: 8,
        cursorwidth: "6px",
        background: "rgba(0,0,0,.1)",
        autohidemode: false,
        railpadding: {
            top: 0,
            right: 2,
            left: 2,
            bottom: 0
        }
    });
    $(".navigation .dropdown.open").data("closable", false);
    $(".navigation .dropdown").on({
        "shown.bs.dropdown": function() {
            $(this).data("closable", false);
            $("#sidebar").getNiceScroll().resize()
        },
        click: function(d) {
            $(this).data("closable", true);
            if (!$(this).hasClass("open")) {
                $("li.dropdown.open").removeClass("open")
            }
            if ($("#sidebar").hasClass("collapsed")) {
                d.stopPropagation()
            }
            $("#sidebar").getNiceScroll().resize()
        },
        "hide.bs.dropdown": function() {
            return $(this).data("closable");
            $("#sidebar").getNiceScroll().resize()
        }
    });
    $(".sidebar-collapse a").on("click", function() {
        $("#sidebar, #navbar").toggleClass("collapsed");
        $(".navigation").find(".dropdown.open").removeClass("open");
        $(".navigation").find(".dropdown-menu.animated").removeClass("animated");
        $("#sidebar > li.collapsed").removeClass("collapsed");
        if ($("#sidebar").hasClass("collapsed")) {
            if ($(window).width() < 1024) {
                $("#content").animate({
                    left: "0px"//265px
                }, 150)
            } else {
                $("#content").animate({
                    paddingLeft: "55px"
                }, 150)
            }
        } else {
            if ($(window).width() < 1024) {
                $("#content").animate({
                    left: "210px"
                }, 150)
            } else {
                $("#content").animate({
                    paddingLeft: "265px"
                }, 150)
            }
        }
    });
    $(".navigation .menu > li").hover(function() {
        $(this).addClass("hovered");
        $("#sidebar").addClass("open")
    }, function() {
        $(this).removeClass("hovered");
        $("#sidebar").removeClass("open")
    });
    widthLess1024();
    $(window).resize(function() {
        widthLess1024();
    });
    $('#LoginOut').click(function(){
        var loading;
        var url = $(this).data('url');
        layer.confirm("确认退出？",{
            btn: ["确认","取消"]
        },function(){
            $.ajax({
                type: "POST",
                dataType: "json",
                url: url,
                beforeSend:function(){
                    loading = layer.load(1,{
                        shade: [0.7,'#000']
                    });
                },success:function(data){
                    layer.close(loading);
                    if(data.Code == 1){
                        layer.msg(data.Msgs,{icon: 1,time: data.Wait});
                        window.setTimeout(function(){
                            window.location.href = data.Urls;
                        },data.Wait);
                    }
                },error:function(){           
                    layer.close(loading);
                    layer.open({
                        icon: 7,
                        title: "系统提示",
                        content: "网络错误"
                    });
                }
            });
        });
    });
});
$(window).on("load",function(){
    $(".mask").delay(800).fadeOut(300, function() {
        widthLess1024();
    })
})